package com.camel.auth.config;

import cn.dev33.satoken.stp.StpInterface;
import com.camel.auth.service.ISysUserService;
import com.camel.core.config.IamApplicationconfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author camel
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private ISysUserService userService;
    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 本list仅做模拟，实际项目中要根据具体业务逻辑来查询权限
        if(loginId.equals(IamApplicationconfig.ROOT_USER_ID_STRING_VALUE)) {
            return userService.selectRootMenu();
        }
        return userService.selectUserMenu(Integer.parseInt((String) loginId));
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 本list仅做模拟，实际项目中要根据具体业务逻辑来查询角色
        List<String> list = new ArrayList<String>();
        if(loginId.equals(IamApplicationconfig.ADMIN_ROLE_ID_STRING_VALUE)) {
            list.add("admin");
            return list;
        }
        return userService.selectUserRole(Integer.parseInt((String) loginId));
    }
}
